/** @file    VoiceCall.cpp
 *  @author  Alessandro Polo
 *  @version $Id: VoiceCall.cpp 2621 2010-06-04 12:23:48Z alex $
 *  @brief
 * File containing methods for the wosh::communication::VoiceCall class.
 * The header for this class can be found in VoiceCall.h, check that file
 * for class description.
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/
 
 #include <framework/communication/VoiceCall.h>

 #include <core/ObjectAllocator.h>
 #include <core/Utilities.h>


using namespace std;
namespace wosh {
 namespace communication {

 WOSH_REGISTER(wosh::communication::VoiceCall, "wosh::Notification", 1.0, _static_VoiceCall )

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////// CONSTRUCTORS

VoiceCall::VoiceCall()
	: Notification() {
	clear();
 }


VoiceCall::VoiceCall( const VoiceCall& m )
	: Notification(m) {
	clear();
	*this = m;
 }

//////////////////////////////////////////////////////////////////////////////////////////////// CONSTRUCTORS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////// CONFIGURATION

void VoiceCall::clear() {
	Notification::clear();
	this->duration = 0;
	this->textmessage = "";
	this->callType = VoiceCall::CALL_UNKNOWN_TYPE;
	this->callStatus = VoiceCall::STATUS_IDLE;
 }


VoiceCall& VoiceCall::operator=( const VoiceCall& m ) {
	if (this == &m) return *this; // same object?

	(Notification&)*this = (const Notification&)m;

	this->duration = m.duration;

	this->callType = m.callType;
	this->callStatus = m.callStatus;

	return *this;
 }

bool VoiceCall::operator==( const VoiceCall &other ) const {
	if ( (Notification&)*this != (const Notification&)other )
		return false;

	return true;
 }

//////////////////////////////////////////////////////////////////////////////////////////////// DEBUG & INFO
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

std::string VoiceCall::getCallSummary() const {
	string res = "";
	res += getCallTypeAsString(this->callType);
	res += " ";
	res += getCallStatusAsString(this->callStatus);
	res += "call";
	return res;
 }

/////////////////////////////////////////////////////////////////////////////////////////////// SERIALIZATION

std::string VoiceCall::toString() const {
	return Utilities::format("VoiceCall[FileMessage]#%ld", this->uid);
 }

bool VoiceCall::updateHash( DataHashContext* hash_context ) const {
	if ( hash_context == NULL ) return false;
	bool ret = Notification::updateHash( hash_context );
	ret = hash_context->update( this->duration ) & ret;
	ret = hash_context->update( this->callStatus ) & ret;
	ret = hash_context->update( this->callType ) & ret;
	ret = hash_context->update( this->textmessage ) & ret;
	return ret;
 }

/////////////////////////////////////////////////////////////////////////////////////////////// SERIALIZATION
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

VoiceCall::CALL_TYPE VoiceCall::getCallTypeFromString( const std::string& type ) {
	if ( type == "INCOMING" )
		return VoiceCall::CALL_INCOMING;
	else if ( type == "OUTGOING" )
		return VoiceCall::CALL_OUTGOING;
	return VoiceCall::CALL_UNKNOWN_TYPE;
 }

std::string VoiceCall::getCallTypeAsString( VoiceCall::CALL_TYPE type ) {
	switch(type) {
		case VoiceCall::CALL_INCOMING:		return "INCOMING";
		case VoiceCall::CALL_OUTGOING:		return "OUTGOING";
		case VoiceCall::CALL_UNKNOWN_TYPE:
		default:							return "UNKNOWN_TYPE";
	 }
 }

VoiceCall::CALL_STATUS VoiceCall::getCallStatusFromString( const std::string& status )
 {
	if ( status == "IDLE" )
		return VoiceCall::STATUS_IDLE;
	else if ( status == "DIALING" )
		return VoiceCall::STATUS_DIALING;
	else if ( status == "RINGING" )
		return VoiceCall::STATUS_RINGING;
	else if ( status == "CONNECTED" )
		return VoiceCall::STATUS_CONNECTED;
	else if ( status == "DISCONNECTED" )
		return VoiceCall::STATUS_DISCONNECTED;
	return VoiceCall::STATUS_UNKNOWN;
 }

std::string VoiceCall::getCallStatusAsString( VoiceCall::CALL_STATUS status )
 {
	switch(status) {
		case VoiceCall::STATUS_IDLE:		return "IDLE";
		case VoiceCall::STATUS_DIALING:		return "DIALING";
		case VoiceCall::STATUS_RINGING:		return "RINGING";
		case VoiceCall::STATUS_CONNECTED:	return "CONNECTED";
		case VoiceCall::STATUS_DISCONNECTED:return "DISCONNECTED";
		case VoiceCall::STATUS_UNKNOWN:
		default:							return "STATUS_UNKNOWN";
	 }
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 }; // namespace communication
}; // namespace wosh
